package com.company;

/**
 * @author zhf
 * @date 2021/10/9
 */
public class maxarea {


    public static void main(String[] args) {
        int[] height = new int[]{1,8,6,2,5,4,8,3,7};
        maxarea maxare = new maxarea();
        int are = maxare.maxArea(height);
        System.out.println(are);
    }
    public int maxArea(int[] height) {
        int len = height.length;
        int l = 0;   //左指针
        int r = len-1;  //右指针
        int maxAre = 0;
        while (l<r){
            int tempare = Math.min(height[r],height[l]) * (r-l);
            maxAre = Math.max(tempare,maxAre);
            if (height[l] <= height[r]){
                l++;
            }else {
                r--;
            }
        }
        return maxAre;
    }
}
